package network;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

// 实现一个"英译汉"服务器
public class UDPDictServer extends UDPEchoServer {

    private Map<String,String> dict=new HashMap<String,String>();

    public UDPDictServer(int port) throws SocketException {
        super(port);
        dict.put("cat","猫");
        dict.put("dog","狗");
        dict.put("pig","猪");
        dict.put("sheep","羊");
    }

    @Override
    public String process(String request) {
        return dict.getOrDefault(request,"未知单词");
    }

    public static void main(String[] args) throws IOException {
        UDPDictServer server=new UDPDictServer(9090);
        server.start();
    }
}
